using UnityEngine;

namespace Audio
{
    [RequireComponent(typeof(AudioSource))]
    public class AudioPlayer : MonoBehaviour
    {
        public static AudioPlayer Instance { get; private set; }

        private AudioSource _audioSource;

        
        private void Awake()
        {
            Instance = this;
            _audioSource = GetComponent<AudioSource>();
        }

        public void PlaySound(AudioClip audioClip)
        {
            _audioSource.PlayOneShot(audioClip);
        }

        /// <summary>
        /// 从给定的clips中随机播放一个
        /// </summary>
        /// <param name="audioClips"></param>
        public void PlayRandom(params AudioClip[] audioClips)
        {
            int index = Random.Range(0, audioClips.Length);
            PlaySound(audioClips[index]);
        }
    }
}

